package sz.szsmk.citizencard.mvp.presenter;

import android.content.Context;

import com.google.gson.Gson;

import javax.inject.Inject;

import rx.functions.Action1;
import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.QueryCitizenCardReq;
import sz.szsmk.citizencard.model.network.bean.request.UserBehaviorBrowseReq;
import sz.szsmk.citizencard.model.network.bean.response.BaseBean;
import sz.szsmk.citizencard.model.network.bean.response.QueryCitizenCardRes;
import sz.szsmk.citizencard.mvp.contract.IMycitycardContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.ui.activity.MyCityCardActivity;
import sz.szsmk.citizencard.util.ACache;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/1/6 16:03
 * description:
 */
public class MycitycardPresenter extends IBasePresenter
        implements IMycitycardContact.IMycitycardPresenter<IMycitycardContact.IMycitycardView> {

    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public MycitycardPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    @Override
    public void queryCitizenCard(Context context) {
        QueryCitizenCardReq queryCitizenCardReq = new QueryCitizenCardReq();
        queryCitizenCardReq.setType("0");
        String json = new Gson().toJson(queryCitizenCardReq);
        mNetworkDateSource.queryCitizenCard(queryCitizenCardReq, new SubscribeResult<QueryCitizenCardRes>() {
            @Override
            protected void onOk(QueryCitizenCardRes response) {
                String json = new Gson().toJson(response);
                ((IMycitycardContact.IMycitycardView) mView).queryCitizenCardSucc(response);
            }

            @Override
            protected void onFailure(QueryCitizenCardRes response) {
                ((IMycitycardContact.IMycitycardView) mView).queryCitizenCardFail();
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void userBehaviorBrowse() {
        UserBehaviorBrowseReq userBehaviorBrowseReq = new UserBehaviorBrowseReq();
        userBehaviorBrowseReq.setModularId( 11  );
        userBehaviorBrowseReq.setAccessToken(ACache.get(DaggerApplication.getIns()).getAsString("access_token"));

        mNetworkDateSource.userBehaviorBrowse(userBehaviorBrowseReq, new Action1<BaseBean>() {
            @Override
            public void call(BaseBean baseBean) {
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }


}
